﻿<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Collections.Generic"%>
<%@ Import Namespace="TarreOA.TarreOABLL"%>
<%@ Import Namespace="TarreOA.TarreOAModels"%>
<%@ Import Namespace="System.Data"%>

<script runat="server">
    
    private PagedDataSource pds;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.NewPagedDataSource(); 
            this.DataList1_DataBind();
            ViewState["pg_in"] = pds.CurrentPageIndex; 
        }
    }

    private void NewPagedDataSource()
    {
        pds = new PagedDataSource();
        pds.AllowPaging = true;
        pds.PageSize = 5;
        this.DataList1_DataTable();
    }

    protected void DataList1_DataBind()
    {
        this.DataList1.DataSource = pds;
        this.DataList1.DataBind(); 
    }

    protected void DataList1_DataTable()
    {
        User curLoginUser = (User)Session["user"];
        UserDiarytbService userDiarytbService = new UserDiarytbService();
        List<UserDiary> list = userDiarytbService.findByUserLoginName(curLoginUser.LoginName);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable(); 
        if (list != null && list.Count > 0)
        {
            dt.Columns.Add("DiaryId", typeof(string));
            dt.Columns.Add("DiaryTitle", typeof(string)); 
            dt.Columns.Add("RegisterTime", typeof(string));
            foreach (UserDiary userDiary in list)
            {
                DataRow dr = dt.NewRow();
                dr["DiaryId"] = userDiary.DiaryId.ToString();
                dr["RegisterTime"] = userDiary.RegisterTime.ToString();
                string diaryTitle = userDiary.DiaryTitle;
                if (diaryTitle.Length > 26)
                {
                    diaryTitle = diaryTitle.Substring(0, 26) + "...";
                }
                dr["DiaryTitle"] = diaryTitle;
                dt.Rows.Add(dr);
            }
        }
        ds.Tables.Add(dt);   
        pds.DataSource = ds.Tables[0].DefaultView;      
    }

    protected void btnGoTop_Click(object sender, EventArgs e)
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }  
        pds.CurrentPageIndex = 0;
        this.DataList1_DataBind();
        ViewState["pg_in"] = pds.CurrentPageIndex; 
    }

    protected void btnRetu_Click(object sender, EventArgs e)
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }  
        pds.CurrentPageIndex--;
        this.DataList1_DataBind();
        ViewState["pg_in"] = pds.CurrentPageIndex;  
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex++;
        this.DataList1_DataBind();
        ViewState["pg_in"] = pds.CurrentPageIndex;   
    }

    protected void btnGoLast_Click(object sender, EventArgs e)
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        pds.CurrentPageIndex = pds.PageCount - 1;
        this.DataList1_DataBind();
        ViewState["pg_in"] = pds.CurrentPageIndex;    
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string did = ((HtmlInputHidden)e.Item.FindControl("diaryId")).Value;
            ((HyperLink)e.Item.FindControl("hplDiaryContent")).Target = "DiaryContentFrame"; 
            ((HyperLink)e.Item.FindControl("hplDiaryContent")).NavigateUrl = "DiaryContent.aspx?did=" + did;
        }
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (pds.IsFirstPage)
            {
                ((Button)e.Item.FindControl("btnRetu")).Enabled = false;
                ((Button)e.Item.FindControl("btnGoTop")).Enabled = false;
            }
            if (pds.IsLastPage)
            {
                ((Button)e.Item.FindControl("btnNext")).Enabled = false;
                ((Button)e.Item.FindControl("btnGoLast")).Enabled = false;
            } 
        }   
    }

    protected void btnDelMsg_Click(object sender, EventArgs e)
    {
        this.NewPagedDataSource();
        if (ViewState["pg_in"] != null)
        {
            pds.CurrentPageIndex = (int)ViewState["pg_in"];
        }
        string[] dids = Request.Params.GetValues("chkCur");
        UserDiarytbService userDiarytbService = new UserDiarytbService();
        userDiarytbService.delDiaryInfoByDiaryId(dids);
        int cp = pds.CurrentPageIndex; 
        this.DataList1_DataTable();
        if (pds.PageCount == cp)
        {
            pds.CurrentPageIndex = pds.PageCount - 1;
        }
        else
        {
            pds.CurrentPageIndex = cp; 
        }   
        this.DataList1_DataBind();
        ViewState["pg_in"] = pds.CurrentPageIndex;     
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title>

    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../js/MyOption.js"></script>

<style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>

</head>
<body>
<form id="form1" runat="server">
<div class="sub_right_top">
    <div class="hdm_footer">
    <!--我的日记-->
	<div id="tb1_1_content" class="cont01_word"  style="display:block;">
       <div class="sub_work_plan">
            <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
            <HeaderTemplate>
            <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" class="dataList" align="center">
			<tr class="jsmail_bgcolor">
				<td style="width: 20%;">
                    <input id="chkAll" onclick="allMsgCheck('chkCur')" type="checkbox" />
                </td>
                <td style="width: 40%;">计划标题</td>
               <td style="width: 40%;">记录时间</td>
			</tr>
			</HeaderTemplate>
			<ItemTemplate>
			<tr>
				<td>
                    <input id="chkCur" name="chkCur" type="checkbox" value='<%# Eval("DiaryId") %>' />
                 </td>
                 <td>
                        <asp:HyperLink ID="hplDiaryContent" runat="server" Font-Size="Small" ForeColor="Teal" Text='<%# Eval("DiaryTitle") %>'></asp:HyperLink>
				        <input id="diaryId" runat="server" type="hidden" value='<%# Eval("DiaryId") %>'/>
                 </td>
                 <td>
                        <asp:Label ID="lblSendDateTime" runat="server" Text='<%# Eval("RegisterTime") %>' ForeColor="Teal" Width="122px"></asp:Label>
                 </td>
			</tr>
			</ItemTemplate>
			<FooterTemplate>
			<tr class="jsmail_bgcolor">
                <td><input id="chkAll" onclick="allMsgCheck('chkCur')" type="checkbox" /></td>
				<td colspan="2" align="right" style="border-left-width:0;">
                    <span style=" float: left;">
                         <asp:Button ID="btnDelMsg" runat="server" BorderStyle="Groove" OnClientClick="return checkDelMsg('chkCur')" Text="删除" Width="58px"
					    OnClick="btnDelMsg_Click" />
                    </span>
                   

                    <asp:Button ID="btnGoTop" runat="server" BorderStyle="Groove" Height="24px" Text="首页" Width="58px" OnClick="btnGoTop_Click" /> &nbsp;
                   
                    <asp:Button ID="btnRetu" runat="server" BorderStyle="Groove" Text="上一页" OnClick="btnRetu_Click" />&nbsp;

                    <asp:Button ID="btnNext" runat="server" BorderStyle="Groove" Text="下一页" OnClick="btnNext_Click" /> 
                    
                    <asp:Button ID="btnGoLast" runat="server" BorderStyle="Groove" Height="24px" Text="末页" Width="58px" OnClick="btnGoLast_Click" /> 
                    
                    <asp:Label ID="lblPageState" runat="server" Width="126px"></asp:Label>
                    </td>
			</tr>
            </table>
			</FooterTemplate>
		</asp:Repeater>
       </div>
<table cellpadding="0" cellspacing="0" align="center" width="100%">
	<tr>
		<td><iframe frameborder="0" name="DiaryContentFrame"
			scrolling="auto" src="WriteDiary.aspx"
			style="width: 100%; height: 350px"></iframe></td>
	</tr>
</table>
</div>
</div>
</form>
</body>
</html>
